React Props 就像 JavaScript 中的函數參數
和HTML 中的屬性。
const myElement = <Car brand="Toyota" />;
class Car extends React.Component {
render(){
return <h2>I love {this.props.brand}!</h2>
}
};
完整程式碼
import React from "react";
import ReactDOM from "react-dom";
class Car extends React.Component {
render(){
return <h2>I love {this.props.brand}!</h2>
}
};
const myElement = <Car brand="Toyota" />;
ReactDOM.render(myElement, document.getElementById('root'));
輸出結果>>>
I love Toyota!
參考來源:
https://www.w3schools.com/react/react_props.asp